const mongoose = require('mongoose');
const articleSchema = new mongoose.Schema({
  title: {
    type: String,
    minlength: 2,
    maxlength: 30,
    required: [true,'请填写文章标题！！！']
  },
  author: {
    type: mongoose.Schema.Types.ObjectId,
    ref: 'User',
    required: [true,'请传递作者']
  },
  publishDate: {
    type: Date,
    default: Date.now()
  },
  cover: {
    type: String,
    default: null
  },
  content: {
    type: String
  },
  classify: {
    type: mongoose.Schema.Types.ObjectId,
    ref: 'Category',
    required: true
  },
  state: {
    type: Number,
    required: true,
    default: 0
  },
  readCount: {
    type: Number,
    default: 0
  }
});
const Article = mongoose.model('Article',articleSchema);
/*Article.create({
  title: '第一篇测试文章',
  author: 'admin',
  publishDate: Date.now(),
  content: '哈哈哈哈哈哈哈哈哈哈哈',
  cover: '\\uploads\\upload_41614d3fb975a3dbce1030bf12de166c.png',
  classify: 'JavaScript',
  state: 1,
  readCount: 0
}).then(()=>{
  console.log('文章创建成功！');
}).catch(()=>{
  console.log('文章创建失败！');
})*/
module.exports = {
  Article
}